﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FrameWork.Lib;
using FrameWork.Lib.DataObjects;
using FrameWork.WinUI.Common;
using FrameWork.WinUI.Controls;

namespace REVISIONMAX30.Controls
{
    public partial class MyLogList : UserControl
    {
        public MyLogList()
        {
            InitializeComponent();
        }

        public UIManager UIManager { get; set; }
        public DataObjects.Group Group { get; set; }

        public void Init(DataObjects.Group pParentObject)
        {
            this.Group = pParentObject;
            this.UpdateViewer();
        }

        public void UpdateViewer()
        {
            this.lvLogs.Items.Clear();

         
            foreach (var sqlItem in this.Group.SQLItemList.Where(t => t.LastExecutionResult != null).OrderByDescending(t => t.Executed))
            {
                var tvlItem = this.lvLogs.Items.Add(sqlItem.LastExecutionResult.Message);

                tvlItem.Tag = sqlItem.DataObjectGUID;
                tvlItem.SubItems.Add(sqlItem.Executed.StringValueOrEmpty("MM/dd/yyyy HH:mm"));
              

            }
        }

        private void lvLogs_DoubleClick(object sender, EventArgs e)
        {
            //if (this.lvLogs.SelectedItems.Count > 0)
            //{
            //    var tSelectedGUID = (Guid)this.lvLogs.SelectedItems[0].Tag;
            //    this.UIManager.ViewConnectionString(this.Group..Where(t => t.DataObjectGUID == tSelectedGUID).First(), this.Group);
            //    this.UpdateViewer();
            //}
        }
    }
}
